package com.google.zxing.client.android;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class GridAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<Integer> mListAppInfo;

	public GridAdapter(Context context, ArrayList<Integer> list) {
		mContext = context;
		mListAppInfo = list;

	}

	@Override
	public int getCount() {
		return mListAppInfo.size();
	}

	@Override
	public Object getItem(int position) {
		return mListAppInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = LayoutInflater.from(mContext);
		convertView = inflater.inflate(R.layout.grid_image, null);

		ImageView ivResult = (ImageView) convertView
				.findViewById(R.id.resultImage);

		if (mListAppInfo.get(position) != 0)
			ivResult.setImageResource(mListAppInfo.get(position));

		return convertView;
	}

	static class ViewHolder {
		ImageView ivResult;
	}

}
